package com.xnfh.home.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.xnfh.framework.base.BaseActivity
import com.xnfh.framework.utils.getStringFromResource
import com.xnfh.home.R
import com.xnfh.home.databinding.ActivityClubDetaliBinding
import com.xnfh.home.ui.fragment.FieldDynamicsFragment
import com.xnfh.home.ui.fragment.PlantingSchemeFragment
import com.xnfh.home.viewmodel.ClubDetailViewModel

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2024/1/5 13:39
 * @UpdateUser: ziheng
 * @UpdateDate: 2024/1/5 13:39
 * @UpdateRemark: 更新说明
 */
class ClubDetailActivity: BaseActivity<ActivityClubDetaliBinding>() {
    override fun getLayoutID(): Int = R.layout.activity_club_detali
    companion object {
        //传入name 在PlantingSchemeFragment用到
        fun start(context: Context, bundle: Bundle? = null) {
            val intent = Intent(context, ClubDetailActivity::class.java)
            if (bundle != null) {
                intent.putExtra("bundle", bundle)
            }
            context.startActivity(intent)
        }
    }

    private val mTitles = arrayOf(
        getStringFromResource(R.string.planting_program),
        getStringFromResource(R.string.str_tj_dt)
    )
    private val mFragments = ArrayList<Fragment>()
    private var mAdapter: MyPagerAdapter? = null

    override fun init() {
        val bundleExtra = intent.getBundleExtra("bundle")
        val name = bundleExtra?.getString("name")
        setHeaderTitle(name)
        mFragments.add(PlantingSchemeFragment())//种植方案
        mFragments.add(FieldDynamicsFragment())//田间动态
        mAdapter = MyPagerAdapter(
            supportFragmentManager
        )
        mBind.clubDetailViewPager.adapter = mAdapter
        mBind.clubDetailSlidingTabLayout.setViewPager(mBind.clubDetailViewPager)
        mBind.clubDetailViewPager.currentItem = 0
    }

    override fun observe() {
    }
    inner class MyPagerAdapter(fm: FragmentManager?) :
        FragmentPagerAdapter(fm!!) {
        override fun getCount(): Int {
            return mFragments.size
        }

        override fun getPageTitle(position: Int): CharSequence {
            return mTitles[position]
        }

        override fun getItem(position: Int): Fragment {
            return mFragments[position]
        }
    }
}